package com.smart.manage.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.smart.common.utils.DateUtils;
import com.smart.manage.domain.DoctorConsultation;
import com.smart.manage.mapper.DoctorConsultationMapper;
import com.smart.system.mapper.SysUserRoleMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.manage.domain.PatientsConsultation;
import com.smart.manage.service.IPatientsConsultationService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 在线问诊Controller
 * 
 * @author lingyao
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/manage/patientsConsultation")
public class PatientsConsultationController extends BaseController
{
    @Autowired
    private IPatientsConsultationService patientsConsultationService;

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Autowired
    private DoctorConsultationMapper doctorConsultationMapper;

    /**
     * 查询在线问诊列表
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsConsultation:list')")
    @GetMapping("/list")
    public TableDataInfo list(PatientsConsultation patientsConsultation)
    {
        Long userId = getUserId();
        Long roleId = sysUserRoleMapper.selectRoleIdByUserId(userId);
        if (roleId != 1) {
            patientsConsultation.setUserId(userId);
        }
        startPage();
        List<PatientsConsultation> list = patientsConsultationService.selectPatientsConsultationList(patientsConsultation);
        return getDataTable(list);
    }

    /**
     * 导出在线问诊列表
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsConsultation:export')")
    @Log(title = "在线问诊", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PatientsConsultation patientsConsultation)
    {
        List<PatientsConsultation> list = patientsConsultationService.selectPatientsConsultationList(patientsConsultation);
        ExcelUtil<PatientsConsultation> util = new ExcelUtil<PatientsConsultation>(PatientsConsultation.class);
        util.exportExcel(response, list, "在线问诊数据");
    }

    /**
     * 获取在线问诊详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsConsultation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(patientsConsultationService.selectPatientsConsultationById(id));
    }

    /**
     * 新增在线问诊
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsConsultation:add')")
    @Log(title = "在线问诊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PatientsConsultation patientsConsultation)
    {
        Long userId = getUserId();
        patientsConsultation.setUserId(userId);
        return toAjax(patientsConsultationService.insertPatientsConsultation(patientsConsultation));
    }

    /**
     * 修改在线问诊
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsConsultation:edit')")
    @Log(title = "在线问诊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PatientsConsultation patientsConsultation)
    {
        return toAjax(patientsConsultationService.updatePatientsConsultation(patientsConsultation));
    }

    /**
     * 删除在线问诊
     */
    @PreAuthorize("@ss.hasPermi('manage:patientsConsultation:remove')")
    @Log(title = "在线问诊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(patientsConsultationService.deletePatientsConsultationByIds(ids));
    }
}
